import path from 'path';
import fs from 'fs-extra';
import {
	defineConfig
} from 'vite';
import uni from '@dcloudio/vite-plugin-uni';

import h5ProdEffectPlugin from 'uni-vite-plugin-h5-prod-effect'

import { plugins as postcssPlugins } from './postcss.config.js'

import uniReadPagesV3Plugin from './infrastructure/utils/uni-read-pages-v3.js';

import uniHot from 'uni-pages-hot-modules'

import {replacePreprocess} from './common.js'

// 安装条件编译命令，安装之后，uniapp就会支持exec hotJs的条件编译
uniHot.setupHotJs()

replacePreprocess()

const pages = require('./pages.js');


export default defineConfig({
	root: __dirname,
	plugins: [
		uni(),
		h5ProdEffectPlugin(),
		uniHot.createHotVitePlugin(),
		uniReadPagesV3Plugin({
			pagesJson: pages,
			includes: ['path', 'aliasPath', 'name', 'meta'],
		})
		
	],
	build: { //发布时删除 console
		// minify: 'terser',
		// terserOptions: {
		// 	compress: {
		// 		drop_console: true,
		// 	},
		// },
	},
	server: {
		port: 20000
	}
  ,css: {
    postcss: {
      plugins: postcssPlugins
      
    }
  }

});

